package com.ruoyi.project.jiaqin.industry.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.jiaqin.industry.domain.JiaqinIndustry;
import com.ruoyi.project.jiaqin.industry.service.IJiaqinIndustryService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 行业Controller
 * 
 * @author admin
 * @date 2020-12-30
 */
@Controller
@RequestMapping("/jiaqin/industry")
public class JiaqinIndustryController extends BaseController
{
    private String prefix = "jiaqin/industry";

    @Autowired
    private IJiaqinIndustryService jiaqinIndustryService;

    @RequiresPermissions("jiaqin:industry:view")
    @GetMapping()
    public String industry()
    {
        return prefix + "/industry";
    }

    /**
     * 查询行业列表
     */
    @RequiresPermissions("jiaqin:industry:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiaqinIndustry jiaqinIndustry)
    {
        startPage();
        List<JiaqinIndustry> list = jiaqinIndustryService.selectJiaqinIndustryList(jiaqinIndustry);
        return getDataTable(list);
    }

    /**
     * 导出行业列表
     */
    @RequiresPermissions("jiaqin:industry:export")
    @Log(title = "行业", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiaqinIndustry jiaqinIndustry)
    {
        List<JiaqinIndustry> list = jiaqinIndustryService.selectJiaqinIndustryList(jiaqinIndustry);
        ExcelUtil<JiaqinIndustry> util = new ExcelUtil<JiaqinIndustry>(JiaqinIndustry.class);
        return util.exportExcel(list, "industry");
    }

    /**
     * 新增行业
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存行业
     */
    @RequiresPermissions("jiaqin:industry:add")
    @Log(title = "行业", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiaqinIndustry jiaqinIndustry)
    {
        return toAjax(jiaqinIndustryService.insertJiaqinIndustry(jiaqinIndustry));
    }

    /**
     * 修改行业
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        JiaqinIndustry jiaqinIndustry = jiaqinIndustryService.selectJiaqinIndustryById(id);
        mmap.put("jiaqinIndustry", jiaqinIndustry);
        return prefix + "/edit";
    }

    /**
     * 修改保存行业
     */
    @RequiresPermissions("jiaqin:industry:edit")
    @Log(title = "行业", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiaqinIndustry jiaqinIndustry)
    {
        return toAjax(jiaqinIndustryService.updateJiaqinIndustry(jiaqinIndustry));
    }

    /**
     * 删除行业
     */
    @RequiresPermissions("jiaqin:industry:remove")
    @Log(title = "行业", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiaqinIndustryService.deleteJiaqinIndustryByIds(ids));
    }
}
